package com.woniuxy.handler;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.annotation.SystemLog;
import com.woniuxy.mapper.LogMapper;
import com.woniuxy.service.LogsService;
import com.work.framework.pojo.Logs;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 〈日志接口〉
 *
 * @author mjh
 * @create 2019/9/20
 */

@RestController
@RequestMapping("/log")
@Api(value = "日志查询")
public class LogHandler {

    @Autowired
    LogsService logsService;

    @RequestMapping("/all")
    @ApiOperation(value = "查询所有日志", notes = "查询所有，返回logs的列表")
    @SystemLog(module = "系统管理", operation_description = "查看所有日志记录")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "", value = "")
    )
    public List<Logs> showAll(int page) {
        //System.out.println(IPUtil.getIPFromRequest(request));
        //PageHelper.startPage(2,2);
        System.out.println(logsService.findAll(page));
        return logsService.findAll(page);
    }

    @RequestMapping("/alls")
    public PageInfo<Logs> All(int page) {
        System.out.println("pageInfo:" + logsService.All(page));
        return logsService.All(page);
    }

    @RequestMapping("/byLike")
    public PageInfo<Logs> findByCondition(Logs logs,Integer page ) {
//        Logs logs = new Logs();
//        logs.setAccount("155");
//        logs.setStartTime("2019-09-25 16:45:00");Logs logs,
//        logs.setEndTime("2019-09-25 16:45:18");

        if(page==null){
            page = 1;
        }

        System.out.println("logs:" + logs);

        return logsService.findByLike(logs,page);
    }
}
